/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.commands;

import edu.wpi.first.wpilibj.templates.subsystems.ArmSubsystem;
import edu.wpi.first.wpilibj.templates.subsystems.NewPIDLifterSubsystem;

/**
 *
 * @author matt
 */
public class LifterBalance extends CommandBase {

    private static boolean deployed = false;
    private boolean m_isRunning = false;
    private NewPIDLifterSubsystem lifterOne;
    private NewPIDLifterSubsystem lifterTwo;

    public LifterBalance(NewPIDLifterSubsystem lifterOne, NewPIDLifterSubsystem lifterTwo) {
        // Use requires() here to declare subsystem dependencies
        requires(leftForeLifterSubsystem);
        requires(leftRearLifterSubsystem);
        requires(rightForeLifterSubsystem);
        requires(rightRearLifterSubsystem);

        this.lifterOne = lifterOne;
        this.lifterTwo = lifterTwo;
        System.out.println("LifterBalance constructed " + lifterOne.getName() + " " + lifterTwo.getName());
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        m_isRunning = true;
        // command drives to slow to the point where we can deploy
        leftDriveSubsystem.drive(0);
        rightDriveSubsystem.drive(0);
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        if (/*
                 * left and right are slow enough
                 */true) {
            if (deployed) {
                lifterOne.setLifterPosition(NewPIDLifterSubsystem.LifterPresetLocation.kHighClearance);
                lifterTwo.setLifterPosition(NewPIDLifterSubsystem.LifterPresetLocation.kHighClearance);
                deployed = false;
            } else {
                //armSubsystem.setPosition(ArmSubsystem.ArmPresetLocation.kIntermediate );
                lifterOne.setLifterPosition(NewPIDLifterSubsystem.LifterPresetLocation.kStilt);
                lifterTwo.setLifterPosition(NewPIDLifterSubsystem.LifterPresetLocation.kStilt);
                deployed = true;
            }
            m_isRunning = true;
        }
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return m_isRunning;
    }

    // Called once after isFinished returns true
    protected void end() {
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
    }
}
